<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员面板 - 个人博客</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .admin-header {
            background-color: #343a40;
            color: white;
            padding: 20px 0;
            margin-bottom: 30px;
        }
        .admin-title {
            font-weight: 600;
        }
        .admin-card {
            border-radius: 10px;
            box-shadow: 0 0 15px rgba(0,0,0,0.1);
            margin-bottom: 20px;
        }
        .admin-card .card-header {
            background-color: #007bff;
            color: white;
            font-weight: 600;
            border-top-left-radius: 10px;
            border-top-right-radius: 10px;
        }
        .admin-sidebar {
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 0 15px rgba(0,0,0,0.1);
            padding: 20px;
        }
        .admin-sidebar .nav-link {
            color: #343a40;
            padding: 10px 15px;
            border-radius: 5px;
            margin-bottom: 5px;
        }
        .admin-sidebar .nav-link:hover {
            background-color: #f8f9fa;
        }
        .admin-sidebar .nav-link.active {
            background-color: #007bff;
            color: white;
        }
        .admin-sidebar .nav-link i {
            margin-right: 10px;
        }
        .user-table th, .user-table td {
            vertical-align: middle;
        }
    </style>
</head>
<body>
    <div class="admin-header">
        <div class="container">
            <div class="row align-items-center">
                <div class="col-md-6">
                    <h1 class="admin-title">管理员面板</h1>
                </div>
                <div class="col-md-6 text-end">
                    <span sec:authentication="name" class="me-3"></span>
                    <a th:href="@{/logout}" class="btn btn-outline-light">退出登录</a>
                </div>
            </div>
        </div>
    </div>
    
    <div class="container">
        <div class="row">
            <!-- 侧边栏 -->
            <div class="col-md-3">
                <div class="admin-sidebar">
                    <h5 class="mb-3">管理菜单</h5>
                    <div class="nav flex-column">
                        <a class="nav-link active" href="#">
                            <i class="bi bi-people"></i> 用户管理
                        </a>
                        <a class="nav-link" th:href="@{/}">
                            <i class="bi bi-file-earmark-text"></i> 文章列表
                        </a>
                        <a class="nav-link" th:href="@{/posts/new}">
                            <i class="bi bi-file-earmark-plus"></i> 创建文章
                        </a>
                        <a class="nav-link" href="#">
                            <i class="bi bi-gear"></i> 系统设置
                        </a>
                    </div>
                </div>
            </div>
            
            <!-- 主内容区 -->
            <div class="col-md-9">
                <div class="admin-card card">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <h5 class="mb-0">用户管理</h5>
                    </div>
                    <div class="card-body">
                        <div th:if="${message}" class="alert alert-success" th:text="${message}"></div>
                        <div th:if="${error}" class="alert alert-danger" th:text="${error}"></div>
                        
                        <table class="table table-striped user-table">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>用户名</th>
                                    <th>昵称</th>
                                    <th>邮箱</th>
                                    <th>角色</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr th:each="user : ${users}">
                                    <td th:text="${user.id}"></td>
                                    <td th:text="${user.username}"></td>
                                    <td th:text="${user.nickname}"></td>
                                    <td th:text="${user.email}"></td>
                                    <td>
                                        <span th:each="role : ${user.roles}" class="badge bg-primary me-1" th:text="${role.name.substring(5)}"></span>
                                    </td>
                                    <td>
                                        <span th:if="${user.enabled}" class="badge bg-success">启用</span>
                                        <span th:unless="${user.enabled}" class="badge bg-danger">禁用</span>
                                    </td>
                                    <td>
                                        <div class="btn-group btn-group-sm">
                                            <button class="btn btn-outline-primary">编辑</button>
                                            <button class="btn btn-outline-danger">禁用</button>
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>